/**
 * 部门添加js
 */
var comValidform = null;
var returnStatus = false;
var organizationAdd = {
	parOrgType:null,
	dataCache : null,

	getChannelResource : function() {
		var url = 'mgr/userChannelCtrl/list';
		var params = {
			'curPage' : 0,
			'pageSize' : 9999,
		};

		params.actUserId=userId;
		if(params.actUserId == ''){
			alert("登录超时，请重新登录后重试");
			return false;
		}


		var cb = function(data) {
			if (data.resultCode == 200) {
				var option = '<option value="">请选择所属渠道</option>';
				for (var i = 0; i < data.result.length; i++) {
					var singleObj = data.result[i];
					option = option + '<option value="' + singleObj.id + '">'
						+ singleObj.name + '</option>';
				}
				$('select[name="channel"]').append(option);
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');

	},

	startEvent : function() {
		comValidform = $(".com-addForm").Validform({
			tiptype : 2,
			tipSweep : true,
			beforeSubmit : function(curform) {
				var url = 'mgr/OrganizationCtrl/save';
				var params = jsUtils.serializeJson($('.com-addForm'));

				params.parentID =  $('#com-addForm input[name="parentID"]').val();


				if (organizationAdd.parOrgType != 2) {
					params.channel =  organizationAdd.parOrgType ;



				} else {
					params.channel =  $('#com-addForm select[name="channel"]').val();
				}

				params.actUserId=userId;
				if(params.actUserId == ''){
					alert("登录超时，请重新登录后重试");
					return false;
				}


				var cb = function(data) {
					alert(data.msg);
					// 成功返回
					if (data.resultCode == 200) {
						// 关闭窗口并刷新数据
						//art.dialog.close();
						returnStatus = true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	bindEvent: function() {
		//添加是否是负责人,默认不是
		
		$("#headerTr").hide();
		
		$("select[name='orgType']").change(function() {
			if ($("select[name='orgType']").val() != 4) {
				$("#headerTr").hide();
				$("#depTr").show();

			} else {
				$("#headerTr").show();
				$("#depTr").hide();
			}
		});

		if (organizationAdd.parOrgType != 2) {
			$("#channelTr").hide();
			$("select[name='channel']").attr('type', 'hidden');
			$("select[name='channel']").attr('ignore', 'ignore');
		} else {
			$("select[name='channel']").attr('type', 'text');
			$("select[name='channel']").attr('ignore', '');
			$("#channelTr").show();
		}
	},

	init : function() {
		var parentID = art.dialog.data('parentID');
		var parName = art.dialog.data('parName');
		organizationAdd.parOrgType = art.dialog.data('orgType');

		//alert("organizationAdd.parOrgType = " + organizationAdd.parOrgType);

		$('#com-addForm input[name="parentID"]').val(parentID);
		$('#com-addForm td[name=parName]').html(parName);
		organizationAdd.getChannelResource();
		organizationAdd.startEvent();
		organizationAdd.bindEvent();
	}
}
$(document).ready(function() {
	organizationAdd.init();
});
function submitForm() {
	comValidform.submitForm();
	return returnStatus;
}